package dao;

import java.io.UnsupportedEncodingException;
import java.sql.SQLException;

import tools.Tool;
import Model.Blog;

public class BlogDAO extends DAO{

	public BlogDAO()
	{
		super();
	}
	public boolean addBlog(Blog blog)
	{
		sql="insert into blog(id,text,sourceid,isshow) values(?,?,?,?)";
		try {
			pstmt=conn.prepareStatement(sql);
			pstmt.setString(1, blog.getId());
			pstmt.setString(2, blog.getText());
			/*try {
				String text=new String(blog.getText().getBytes(),"utf-8");
				System.out.println("change to utf-8 text:"+text);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("insert text:"+blog.getText());*/
			pstmt.setString(3, blog.getSourceid());
			pstmt.setInt(4, 1);
			if(pstmt.executeUpdate()==1)
			{
				return true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Tool.PrintException("addblog", "blogDAO");
		}
		return false;
	}
}
